<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>

    <link rel="stylesheet" href="css/logincommon.css">
    <link rel="stylesheet" href="css/login.css">
</head>

<body>
<div class="nav">
    <img src="pic/logo2.jpg" alt="">
    <span class="blog-title">五子棋对战</span>
</div>

<div class="container-login">
    <div class="login-dialog">
        <h3>登录</h3>
        <div class="row">
            <span>用户名</span>
            <input type="text" name="username" id="username">
        </div>
        <div class="row">
            <span>密码</span>
            <input type="password" name="password" id="password">
        </div>
        <div class="row">
            <button id="submit" onclick="login()">登录</button>
        </div>
        <div class="row">
            <span>还没有账号？</span>
            <a href="gobang_register.html">立即注册</a>
        </div>
    </div>
</div>
<script src="js/jquery.min.js"></script>
<script>
     function login() {
        $.ajax({
            type:'post',
            url:'user/login',
            contentType: "application/json",
            data: JSON.stringify({
                "userName": $("#username").val(),
                "password": $("#password").val()
            }),
            success:function(body) {
                console.log(body)
                if(body.message == "账号在别处登录") {
                    alert("账号在别处登录")
                }else if(body.message == "密码错误"){
                    alert("密码错误")
                }else if(body.message == "用户不存在") {
                    alert("用户不存在")
                }else if(body.message == "登录成功") {
                    location.assign('/game_hall.html');
                }else{
                    alert("发生错误")
                }
            }

        });
     }
</script>

</body>

</html>